# main.py
from fastapi import FastAPI
from core.plugin_loader import scan_plugins, route
from core.router import register_routes
from fastapi.routing import APIRoute

# 初始化主应用
app = FastAPI(title="Webman风格自动路由框架")

# 启动时扫描插件并注册路由
plugins = scan_plugins()
# print(plugins,'ppppppppppppp')
register_routes(app, plugins)

# 验证主路由
@app.get("/")
async def root():
    return {"message": "Webman风格自动路由已启动，访问 /plugins/插件名/模块名/... 测试"}
@app.on_event("startup")
async def startup_event():
    routes = []
    for route in app.routes:
        if isinstance(route, APIRoute):
            routes.append({"path": route.path, "methods": route.methods})
    print("已注册路由：", routes)  # 检查是否包含目标路由
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)